package com.bt.lms.ui.page.teaching.arrange;

import com.bt.lms.ui.action.teaching.arrange.PageEditTeachingArrangeCancelBtnAction;
import com.bt.lms.ui.action.teaching.arrange.PageEditTeachingArrangeSaveBtnAction;
import com.bt.lms.ui.action.teaching.arrange.PageEditTeachingArrangeStartCourseBtnAction;
import com.bt.lms.ui.page.sys.style.BtnStyle;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;

/**
 * 编辑教学安排界面
 */
public class PageEditTeachingArrange extends VBox {

    /**
     * 编辑教学安排界面宽
     */
    private double preWidth = 1280;
    /**
     * 编辑教学安排界面高
     */
    private double preHeight = 800;

    public PageEditTeachingArrange(){

        this.setPadding(new Insets(5));
        this.setSpacing(20);
        this.setPrefSize(preWidth,preHeight);
        //顶部横向盒子
        HBox topHBox = new HBox();
        initTopHBox(topHBox);
        //编辑教学安排横向盒子
        HBox editTeachingArrangeHBox = new HBox();
        initEditTeachingArrangeHBox(editTeachingArrangeHBox);
        //网格盒子
        VBox netVBox = new VBox();
        initNetVBox(netVBox);
        //底部盒子
        HBox bottomHBox = new HBox();
        initBottomHBox(bottomHBox);


        //滚动条盒子
        VBox scrollPaneVBox  = new VBox();
        ScrollPane scrollPane = new ScrollPane();
        scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
        scrollPane.setContent(scrollPaneVBox);
        scrollPane.setPrefSize(preWidth,preHeight);

        scrollPaneVBox.getChildren().addAll(topHBox,editTeachingArrangeHBox,netVBox,bottomHBox);


        ObservableList<Node> children = this.getChildren();
        children.addAll(scrollPane);
    }

    /**
     * 底部盒子
     * @param bottomHBox
     */
    private void initBottomHBox(HBox bottomHBox) {

        bottomHBox.setPadding(new Insets(10));
        bottomHBox.setSpacing(20);
        bottomHBox.setAlignment(Pos.CENTER);

        //保存按钮
        Button saveBtn = new Button("保存");

        BtnStyle.saveBtn(saveBtn);
        //保存按钮事件
        PageEditTeachingArrangeSaveBtnAction pageEditTeachingArrangeSaveBtnAction = new PageEditTeachingArrangeSaveBtnAction();
        saveBtn.setOnAction(pageEditTeachingArrangeSaveBtnAction);
        pageEditTeachingArrangeSaveBtnAction.setPageEditTeachingArrange(this);
        saveBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                saveBtn.setCursor(Cursor.HAND);
            }
        });

        //保存并确认开课按钮
        Button startCourseBtn = new Button("保存并确认开课");
        BtnStyle.saveBtn(startCourseBtn);
        startCourseBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                startCourseBtn.setCursor(Cursor.HAND);
            }
        });
        //保存并确认开课按钮事件
        PageEditTeachingArrangeStartCourseBtnAction pageEditTeachingArrangeStartCourseBtnAction = new PageEditTeachingArrangeStartCourseBtnAction();
        startCourseBtn.setOnAction(pageEditTeachingArrangeStartCourseBtnAction);

        //取消按钮
        Button cancelBtn  = new Button("取消");
        BtnStyle.cancelBtn(cancelBtn);
        cancelBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                cancelBtn.setCursor(Cursor.HAND);
            }
        });


        ObservableList<Node> children = bottomHBox.getChildren();
        children.addAll(saveBtn,startCourseBtn,cancelBtn);

        PageEditTeachingArrangeCancelBtnAction pageEditTeachingArrangeCancelBtnAction = new PageEditTeachingArrangeCancelBtnAction();
        cancelBtn.setOnAction(pageEditTeachingArrangeCancelBtnAction);
    }

    /**
     * 网格盒子
     * @param netVBox
     */
    private void initNetVBox(VBox netVBox) {
        netVBox.setSpacing(20);
        netVBox.setPadding(new Insets(2,2,2,20));
        //网格
        GridPane gridPane = new GridPane();
        gridPane.setHgap(15);
        gridPane.setVgap(20);


        //设置课程部分
        //标签
        Label setCourseLab = new Label("设置课程*");
        setCourseLab.setFont(Font.font(null, FontWeight.BOLD,null,16));
        //文本框
        TextField setCourseTF = new TextField("教育心理学");
        setCourseTF.setId("setCourseTF");
        //选择按钮
        Button selectCourseBtn = new Button("选择");
        gridPane.add(setCourseLab,0,1);
        gridPane.add(setCourseTF,1,1);
        gridPane.add(selectCourseBtn,2,1);

        //设置教师部分
        //标签
        Label setTeacherLab = new Label("设置教师*");
        setTeacherLab.setFont(Font.font(null, FontWeight.BOLD,null,16));
        //文本框
        TextField setTeacherTF = new TextField("张老师");
        setTeacherTF.setId("setTeacherTF");
        //选择按钮
        Button selectTeacherBtn = new Button("选择");
        gridPane.add(setTeacherLab,0,2);
        gridPane.add(setTeacherTF,1,2);
        gridPane.add(selectTeacherBtn,2,2);

        //设置学员部分
        //设置学员标签
        Label setStuLab = new Label("设置学员*");
        setStuLab.setFont(Font.font(null, FontWeight.BOLD,null,16));
        //详细文本域
        TextArea detailTA = new TextArea("招生计划A:A班(15/30");
        detailTA.setId("detailTA");
        //选择按钮
        Button selectClassBtn = new Button("选择");
        gridPane.add(setStuLab,0,3);
        gridPane.add(detailTA,1,3);
        gridPane.add(selectClassBtn,2,3);





        //教学方式部分
        //标签
        Label teachingWayLab = new Label("教学方式");
        teachingWayLab.setFont(Font.font(null, FontWeight.BOLD,null,16));
        //下拉框
        ComboBox teachingWayCB = new ComboBox<>();

        teachingWayCB.getItems().add("面授学习");
        teachingWayCB.getItems().add("在线学习");
        teachingWayCB.getItems().add("混合式学习");
        teachingWayCB.getSelectionModel().selectFirst();
        gridPane.add(teachingWayLab,0,4);
        gridPane.add(teachingWayCB,1,4);


        //开课时间部分
        //标签
        Label startCourseLab = new Label("开课时间*");
        startCourseLab.setFont(Font.font(null, FontWeight.BOLD,null,16));
        //日期选择器
        DatePicker startCourseDP = new DatePicker();
        startCourseDP.setId("startCourseDP");
        gridPane.add(startCourseLab,0,5);
        gridPane.add(startCourseDP,1,5);

        //结课时间部分
        //标签
        Label finishCourseLab = new Label("结课时间*");
        finishCourseLab.setFont(Font.font(null, FontWeight.BOLD,null,16));
        //日期选择器
        DatePicker finishCourseDP = new DatePicker();
        finishCourseDP.setId("finishCourseDP");
        gridPane.add(finishCourseLab,0,6);
        gridPane.add(finishCourseDP,1,6);



        //课程目标部分
        //标签
        Label courseAimLab = new Label("课程目标*");
        courseAimLab.setFont(Font.font(null, FontWeight.BOLD,null,16));
        //文本域
        TextArea courseAimTA = new TextArea("为了更好的开展全国教师的培训.....");
        courseAimTA.setId("courseAimTA");
        gridPane.add(courseAimLab,0,7);
        gridPane.add(courseAimTA,1,7);



        //最后修改人部分
        //标签
        Label endPersonLab = new Label("最后修改人");
        endPersonLab.setFont(Font.font(null, FontWeight.BOLD,null,16));
        //人名文本框
        TextField nameTF = new TextField("李某某");
        nameTF.setId("nameTF");
        gridPane.add(endPersonLab,0,8);
        gridPane.add(nameTF,1,8);

        //上次修改时间部分
        //标签
        Label lastTimeLab = new Label("上次修改时间");
        lastTimeLab.setFont(Font.font(null, FontWeight.BOLD,null,16));
        //人名标签
        Label timeLab = new Label("2020-10-01 12：59");
        gridPane.add(lastTimeLab,0,9);
        gridPane.add(timeLab,1,9);




        netVBox.getChildren().addAll(gridPane);
    }

    /**
     * 编辑教学安排横向盒子
     * @param editTeachingArrangeHBox
     */
    private void initEditTeachingArrangeHBox(HBox editTeachingArrangeHBox) {
        editTeachingArrangeHBox.setPadding(new Insets(2));
        //编辑教学安排标签
        Label addTeachingArrangeLab = new Label("编辑教学安排(必修)");
        //设置字体大小
        addTeachingArrangeLab.setFont(Font.font(null, FontWeight.BOLD,null,22));
        addTeachingArrangeLab.setTextFill(Color.rgb(198,0,1));//字体颜色
        editTeachingArrangeHBox.getChildren().addAll(addTeachingArrangeLab);
    }

    /**
     * 顶部横向盒子
     * @param topHBox
     */
    private void initTopHBox(HBox topHBox) {
        topHBox.setSpacing(20);
        topHBox.setPadding(new Insets(2));
        //顶部标签
        Label topLab = new Label("当前位置：🏠>教学管理>教学安排>编辑教学安排(必修课)");
        topLab.setFont(new Font(20));//设置字体大小
        ObservableList<Node> children = topHBox.getChildren();
        children.addAll(topLab);
    }
}
